$(function () {
    //上个页面带过来的id
    var orderBillId = $("#orderBillId").val();
    //发送请求查询数据进行回显
    $.post("/client/selectByOrderBillId?orderBillId=" +orderBillId , function (data) {
        if(data){
            data["aplicant.id"] = data.id;
            $("#client_form").form("load",data);
        }
    });
    $.post("/clientCar/selectByOrderBillId?orderBillId=" + orderBillId,function (data) {
        //console.log(data);
        if(data){
         $("#car_form").form("load",data);
        }
    });
    $.post("/orderBill/selectByOrderBillId?orderBillId=" + orderBillId,function (data) {
        if(data.aplicant){
            data["aplicant.realname"] = data.aplicant.realname;
        }
        if(data){
            $("#time_form").form("load",data);
        }
    });

    $("#revise-panel").panel({
            title: "编辑页面",
            fit:true
    });
    $("#client_panel").panel({
        title: "投保人信息",
        collapsible:true
    });
    $("#time_panel").panel({
        title: "时间信息",
        collapsible:true
    });
    $("#car_panel").panel({
        title: "车辆信息",
        collapsible:true,
        //发送请求查询数据进行回显 (行不通)
        //content:'<iframe src="/client/selectByOrderBillId?orderBillId=" + ${orderBillId} style="width:100%;height:100%" frameborder="0"></iframe>
    });
    //二级联动
    $('#selectedBrand').combobox({
        onSelect: function (row) {
            if (row != null) {
                $('#selectedModel').combobox({
                    url: "/carModel/selectChildByParentId?parentId=" + row.id
                });
            }
        }
    });

    //保存 和 提交审核
    $("a[data-cmd]").on("click",function(){
        var cmd = $(this).data("cmd");
        var  url = "/client/alter1";
        if(cmd == "audit"){
            $.messager.confirm("温馨提示","是否要提交表单和申请核保",function (yes) {
                if(yes){
                    $("#client_form").form("submit",{
                        url:url,
                        onSubmit:function(param){
                            var client = $("input[name='aplicant.id']").val();
                            console.log("客户id" + client);
                            clientId = client;
                            return true;
                        },
                        success: function(data) {
                            data = $.parseJSON(data);
                            if(data.success){
                                $("#car_form").form("submit",{
                                    url:"/clientCar/alter1",
                                    onSubmit:function(param){
                                        // var carModelId = $("input[name='cm_name']").val();
                                        // var carModelId = $("#selectedModel").val();
                                        // carModelId= carModelId;
                                        return true;
                                    },
                                    success: function(data) {
                                        data = $.parseJSON(data);
                                        if(data.success){
                                            $("#time_form").form("submit",{
                                                url:"/orderBill/alter1?id="+ orderBillId + "&stauts=1",
                                                success: function(data) {
                                                    data = $.parseJSON(data);
                                                    if(data.success){
                                                        $.messager.alert("温馨提示",data.msg,"info");
                                                        window.location.href="/orderBill/alter";
                                                    }
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            });
        }else{
            $.messager.confirm("温馨提示","是否要提交表单",function (yes) {
                if(yes){
                    $("#client_form").form("submit",{
                        url:url,
                        onSubmit:function(param){
                            var client = $("input[name='aplicant.id']").val();
                            console.log("客户id" + client);
                            clientId = client;
                            return true;
                        },
                        success: function(data) {
                            data = $.parseJSON(data);
                            if(data.success){
                                $("#car_form").form("submit",{
                                    url:"/clientCar/alter1",
                                    onSubmit:function(param){
                                        // var carModelId = $("input[name='cm_name']").val();
                                        var carModelId = $("#selectedModel").val();
                                        param["carModelIdD"] = carModelId;
                                        return true;
                                    },
                                    success: function(data) {
                                        data = $.parseJSON(data);
                                        if(data.success){
                                            $("#time_form").form("submit",{
                                                url:"/orderBill/alter1?id="+ orderBillId,
                                                success: function(data) {
                                                    data = $.parseJSON(data);
                                                   /* if(data.success){
                                                        $.messager.alert("温馨提示",data.msg,"info");
                                                        window.location.href="/orderBill/alter";
                                                    }*/
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            });
        }

    });
});